package com.jic.purchase.controller;

import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.purchase.model.entity.SupplierRangeProduct;
import com.jic.purchase.model.vo.request.RangeProductRequest;
import com.jic.purchase.model.vo.request.SupplierRangeProductRequest;
import com.jic.purchase.model.vo.response.SupplierRangeProductResponse;
import com.jic.purchase.service.SupplierRangeProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 建投数据科技(山东)有限公司 
 * @date: 2020-05-28 15:28:18
 */
 @RestController
 @Slf4j
 @RequestMapping("/supplierRangeProduct")
 @Api(tags = " [供应商范围商品]控制类-PC")
public class SupplierRangeProductController {
	@Autowired
	private SupplierRangeProductService service;


    /**
     * 分页查询
     *
     * @param request 分页查询请求参数
     * @return 分页列表
     * @throws Throwable 业务异常和系统异常
     */
    @PostMapping("/listPage")
    @ApiOperation(value = " 分页查询列表 ")
    @ResponseBody
    public RestResult<PageResult<SupplierRangeProductResponse>> listPage (@RequestBody SupplierRangeProductRequest request) throws Throwable {
        return RestResult.success(service.querySupplierRangeProductList(request));
    }


    /**
     * 批量保存
     *
     * @param request 分页查询请求参数
     * @return 分页列表
     * @throws Throwable 业务异常和系统异常
     */
    @PostMapping("/batchInsert")
    @ApiOperation(value = " 批量保存 ")
    @ResponseBody
    public RestResult<Boolean> listPage (@RequestBody RangeProductRequest request) throws Throwable {
        return RestResult.success(service.batchInsert(request));
    }

    /**
     * 修改
     *
     * @param request 分页查询请求参数
     * @return 分页列表
     * @throws Throwable 业务异常和系统异常
     */
    @PostMapping("/update")
    @ApiOperation(value = " 修改 ")
    @ResponseBody
    public RestResult<Long> update (@RequestBody SupplierRangeProductRequest request) throws Throwable {
        SupplierRangeProduct supplierRangeProduct = new SupplierRangeProduct();
        BeanUtils.copyProperties(request,supplierRangeProduct);
        return RestResult.success(service.update(supplierRangeProduct));
    }
}

